package com.springStudy.context.annotation.conditional;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

public class MagicExistCondition implements Condition {

    /**
     * 如果返回true，Bean将会被创建并注册到Spring容器中；否则不会创建Bean
     */
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment env = context.getEnvironment();
//        Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes("");
        boolean annotated = metadata.isAnnotated("org.springframework.context.annotation.Configuration");
        // 当定义了magic属性的时候返回true
         env.containsProperty("magic");
        return annotated;
    }

}
